package grammar.parser.stmt;

import error.processing.MyErrorProcessing;
import execution.InOutProcess;
import exp.parser.LVal;
import word.parser.WordElement;

public class GetIntAssign extends Assign {
    public GetIntAssign(LVal lVal) {
        super(lVal);
    }

    public static GetIntAssign buildGetIntAssign(LVal lVal) {
        GetIntAssign assign = new GetIntAssign(lVal);
        assert getAnalyzingWord().getType() == WordElement.WordType.GETINTTK;
        analyzeNextWord();
        assert getAnalyzingWord().getType() == WordElement.WordType.LPARENT;
        analyzeNextWord();
        if (getAnalyzingWord().getType() != WordElement.WordType.RPARENT) {
            MyErrorProcessing.buildErrorProcessing(MyErrorProcessing.ErrorType.j, getAnalyzingWord(-1));
        } else {
            analyzeNextWord();
        }
        return assign;
    }

    @Override
    public void execute() {
        getlVal().assign(InOutProcess.getInt());
    }
}
